#!/bin/bash

usage() {
  echo "Usage: $0 [-h] [-u user]"
  echo
  echo "  -h,        Show this help message"
  echo "  -u,        Define a user (default: pi)"
  exit 1
}

# Default values
user=${SSH_USER:-pi}

while getopts ":hu:" opt; do
  case ${opt} in
    h )
      usage
      ;;
    u )
      user=$OPTARG
      ;;
    \? )
      echo "Invalid Option: -$OPTARG" 1>&2
      usage
      ;;
    : )
      echo "Invalid Option: -$OPTARG requires an argument" 1>&2
      usage
      ;;
  esac
done
shift $((OPTIND -1))

# Don't simply ignore additional arguments
if [ $# -gt 0 ]; then
  echo "Invalid Argument: $1" 1>&2
  usage
fi

echo "You took the red pill."
echo "You stay in Wonderland, and I show you how deep the rabbit hole goes."
echo "Remember, all I'm offering is the truth. Nothing more."
echo "Exiting from docker, welcome to the real world."
ssh -i /root/.config/.ssh/id_rsa -o StrictHostKeyChecking=no $user@localhost
